package com.cm309.hospital.dao;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

public class MyDataSource {
	
	public BasicDataSource ds;
	
	public MyDataSource() {
		
		Properties props = new Properties();
		try {
			props.load(new FileInputStream("D:/Users/HUGONG/Desktop/Hospital/src/"+"jdbc.properties"));
			String dbDriver=props.getProperty("db.driver");
			String dbUrl=props.getProperty("db.url");
			String dbUserName = props.getProperty("db.username");
			String dbPassword = props.getProperty("db.password");
		
System.out.println(dbDriver+"-"+dbUrl+"-"+dbUserName);			
			ds = new BasicDataSource();
			ds.setDriverClassName(dbDriver);
			ds.setUrl(dbUrl);
			ds.setUsername(dbUserName);
			ds.setPassword(dbPassword);
		
			ds.setMaxActive(20);
			ds.setMaxIdle(10);
			ds.setMaxWait(10000);
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public Connection getConnection() throws SQLException{
		return ds.getConnection();
	}
	
	public static void main (String args[]) {
		MyDataSource ds = new MyDataSource();
	}
}
